package org.wdcode.core.lucene.need;

import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.wdcode.common.exception.CustomRuntimeException;
import org.wdcode.common.io.FileUtil;
import org.wdcode.core.params.WdCoreParams;

/**
 * 读取配置的LuceneNeed 使用反射生成类
 * @author WD
 * @since JDK6
 * @version 1.0 2010-05-25
 */
public final class BasicLuceneNeed extends BaseLuceneNeed {
	/**
	 * 初始化
	 */
	@Override
	protected void init() {
		try {
			setIndexPath(WdCoreParams.getLuceneIndexPath());
			setDirectory(FSDirectory.open(FileUtil.getFile(getIndexPath())));
			setVersion(Version.LUCENE_30);
			setAnalyzer(new StandardAnalyzer(getVersion()));
			setCreate(true);
			setMaxFieldLength(IndexWriter.MaxFieldLength.LIMITED);
			setSearcher(new IndexSearcher(getDirectory()));
		} catch (IOException e) {
			throw new CustomRuntimeException(e);
		}
	}
}
